#!/bin/sh
#  
#  This file is part of JunOS Operating System.
#  
#  Copyright (C) 2016, Liu Xiaofeng <lxf.junos@aliyun.com>
#  Licensed under MIT, http://opensource.org/licenses/MIT. 
#

dd if=/dev/zero of=$HOME/ramdisk bs=1M count=2 2> /dev/null
mkfs.minix -1 $HOME/ramdisk > /dev/null

mkdir -p $HOME/tmpdir && sudo mount -t minix $HOME/ramdisk $HOME/tmpdir

echo "Creating root file system ..."
sudo mkdir -p ~/tmpdir/System/Devices
sudo mkdir -p ~/tmpdir/System/Process
sudo mkdir -p ~/tmpdir/System/Volumes
sudo mkdir -p ~/tmpdir/System/Utility
sudo mkdir -p ~/tmpdir/System/Library
sudo mkdir -p ~/tmpdir/System/Setting
sudo mkdir -p ~/tmpdir/Application
sudo mkdir -p ~/tmpdir/User/junos
sudo mkdir -p ~/tmpdir/User/lxf
sudo mkdir -p ~/tmpdir/Data/log

sudo mknod ~/tmpdir/System/Devices/mem     c  1  1
sudo mknod ~/tmpdir/System/Devices/port    c  1  2
sudo mknod ~/tmpdir/System/Devices/null    c  1  3
sudo mknod ~/tmpdir/System/Devices/full    c  1  4
sudo mknod ~/tmpdir/System/Devices/tty     c  2  0
sudo mknod ~/tmpdir/System/Devices/console c  2  1
sudo mknod ~/tmpdir/System/Devices/com1    c  2  2
sudo mknod ~/tmpdir/System/Devices/com2    c  2  3
sudo mknod ~/tmpdir/System/Devices/rd      b  1  0
sudo mknod ~/tmpdir/System/Devices/hda     b  3  0
sudo mknod ~/tmpdir/System/Devices/hda1    b  3  1
sudo mknod ~/tmpdir/System/Devices/hda2    b  3  2

echo "Installing system ..."
sudo make PREFIX=$HOME/tmpdir install

sudo umount $HOME/ramdisk && rm -rf $HOME/tmpdir
mv   $HOME/ramdisk tmp/iso/ramdisk
